package com.yogurt.mp.controller;

import com.yogurt.mp.entity.User;
import com.yogurt.mp.response.user.UserOperatorResponse;
import com.yogurt.mp.service.UserService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/register")
    public UserOperatorResponse register(String telephone, String inviteCode) {
        UserOperatorResponse response = userService.register(telephone, inviteCode);
        return response;
    }

    @GetMapping("/list")
    public List<User> selectUserList() {
        List<User> userList = userService.selectUserList();
        return userList;
    }

    @PostMapping("/a")
    public ResponseEntity<User> aVoid(@RequestBody @Valid User user) {
        return ResponseEntity.ok(userService.selectUserByNickName(user.getNickName()));
    }
}
